< previous page page_445 next page >

Page 445
Next, you would usually normalize the vector by dividing each component by (1 z/d). This step would confuse the Z coordinate information. To preserve the information, normalize only the X and Y components of the point. Then the result becomes:
e10a6a0a59f035e870d90cca05b85fce.gif
[x / (1 - z / d), y / (1 - z / d), z, 1]
The subroutine m3ApplyFull included in module M3Ops.bas applies a perspective transformation matrix to a point. It then normalizes the X and Y coordinates of the result, leaving the Z coordinate unchanged.
e10a6a0a59f035e870d90cca05b85fce.gif
' Apply a transformation matrix to a point where
' the transformation may not have 0, 0, 0, 1 in
' its final column. Normalize only the X and Y
' components of the result to preserve the Z
' information.
Public Sub m3ApplyFull(V() As Single, M() As Single, _
    Result() As Single)
Dim i As Integer
Dim j As Integer
Dim value As Single

    For i = 1 To 4
        value = 0#
        For j = 1 To 4
            value = value + V(j) * M(j, i)
        Next j
        Result(i) = value
    Next i

    ' Renormalize the point.
    ' Note that value still holds Result(4).
    If value <> 0 Then
        Result(1) = Result(1) / value
        Result(2) = Result(2) / value
        ' Do not transform the Z component.
    Else
        ' Make the Z value greater than that of
        ' the center of projection so the point
        ' will be clipped.
        Result(3) = INFINITY
    End If
    Result(4) = 1#
End Sub
Example program Clip, shown in Figure 13.24, demonstrates these techniques. Use the left, right, up, and down arrow keys to change the program's viewing direction. Enter the distance you want between the center of projection and the origin. Click the Clip check box to make the program clip lines behind the center of projection. If you make the distance small (1 or 2), clipping makes a huge difference.

 
< previous page page_445 next page >